package com.example.app.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author wangzhuangzhuang
 * @DESC: 自定义拦截器类
 * @date 2022-02-10 09:24
 */
@Slf4j
@Component
public class CustomHandlerInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		log.info("preHandle:请求前调用");
		// 返回false则请求中断
		return true;
	}
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
	                       ModelAndView modelAndView) throws Exception {
		log.info("postHandle:请求后调用");
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception{
		log.info("afterCompletion:请求调用完成后回调方法，即在视图渲染完成后回调");
	}
}
/**
 * ===》 过滤器（Filter） ===》 拦截器（Interceptor）
 *
 * */